<?php


function int_to_string(&$data,$map=array('status'=>array(0=>'创建申请',1=>'正在采购',2=>'已采购',3=>'提交财务',4=>'财务确认完成，采购完成'))) {
    if($data === false || $data === null ){
        return $data;
    }
    $data = (array)$data;
    foreach ($data as $key => $row){
        foreach ($map as $col=>$pair){
            if(isset($row[$col]) && isset($pair[$row[$col]])){
                $data[$key][$col.'_toString'] = $pair[$row[$col]];
            }
        }
    }
    return $data;
}
function add_log($type,$detail,$batch){
    $data['type']=$type;
    $data['detail']=$detail;
    $data['batch']=$batch;
    $data['uid']=session('userid');
    $data['createdAt']=time();
    $res = M("action_flow")->add($data);
    if($res){
        return true;
    }else{
        return false;
    }
}
function get_batch($type=""){
    $res = M('Purchase_list')->order("createdAt desc")->limit(1)->select();
    if($res[0]['status'] == 4){
        return false;
    }else if ($res[0]['status']==1||$res[0]['status']==2){
        if($type == ""){
            return $res[0];
        }else{
            return $res[0][$type];
        }
    }else{
        return false;
    }
}
function get_provider_name($uid=""){
    $map['id'] = $uid;
    $name = M("Provider")->where($map)->getField('name');
    return $name;
}